from Base.base import Base
from selenium.webdriver.common.by import By
from utils.data_header import read_yaml
import time,os

class login_Page(Base):
    # 获取定位信息
    current_dir = os.path.dirname(__file__)
    test_case = read_yaml(os.path.join(current_dir, '..', 'Config', 'endpoints.yaml'))
    case = test_case[0]

    # 封装输入用户名的方法
    username_loc = (By.CLASS_NAME, case['user'])
    def username(self):
        self.send_keys(self.username_loc, 'admin')

    password_loc = (By.NAME, case['pwd'])
    # 封装输入密码的方法
    def password(self):
        self.send_keys(self.password_loc, '123456')

    loginbtn_loc = (By.CSS_SELECTOR, case['loginbtn'])
    # 封装点击登录按钮的方法
    def loginbtn(self):
        self.click(self.loginbtn_loc)

    def login(self):
        self.open_url('http://49.232.87.188:7009/roncoo-pay-web-boss/login')
        time.sleep(2)
        self.username()
        self.password()
        time.sleep(2)
        self.loginbtn()
        time.sleep(2)
